package main

import "fmt"

func main() {
  var a map[string]int = map[string]int{
    "stu01": 1000,
    "stu02": 2000,
    "stu03": 3000, /*←最后一行需要写个逗号...emmm*/
  }

  var key string = "stu04"
  fmt.Printf("the value of key[%s] is :%d\n", key, a[key]) //the value of key[stu04] is :0 //是该类型的默认值,整数就是0,字符串就是空串

  a["stu04"] = 9999
  fmt.Printf("the value of key[%s] is :%d\n", key, a[key]) //the value of key[stu04] is :9999

  //todo 怎么判断一个map里某个key是否存在
  var key1 string = "stu99"
  value, ok := a[key1] //如果是用两个值接受,第二个变量接受的是bool,表示该key是否存在
  if ok == false {
    fmt.Printf("key1 %s is not exist\n", key1)
  }else{
    fmt.Printf("key1 %s is %d\n",key1, value)
  }
}
